package it.trekker.notifications;

import it.trekker.R;
import it.trekker.activities.ExcursionMainActivity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class NotificationHelper {
	
	private static final int TREKKER_ID = 1;

	public static void buildNotification(Context context) {
		NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
		
		int icon = R.drawable.notification_icon;
		CharSequence tickerText = context.getResources().getString(R.string.app_name);
		long when = System.currentTimeMillis();

		Notification notification = new Notification(icon, tickerText, when);
		notification.flags |= Notification.FLAG_ONGOING_EVENT;
		
		CharSequence contentTitle = context.getResources().getString(R.string.app_name);
		CharSequence contentText = context.getResources().getString(R.string.excursion_in_progress);
		Intent notificationIntent = new Intent(context, ExcursionMainActivity.class);
//		notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//		notificationIntent.setAction("android.intent.action.MAIN");
//		notificationIntent.addCategory("android.intent.category.LAUNCHER");
		
		PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

		notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

		mNotificationManager.notify(TREKKER_ID, notification);
	}
	
	
	public static void removeNotification(Context context) {
		NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
		mNotificationManager.cancel(TREKKER_ID);
	}
	
}
